package com.cos.openapi.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author: COS
 * @time: 2021/1/29 9:06
 * @description: json的统一返回数据类型
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult<T> {
    private Boolean status;
    private String message;
    private T result;

    /**
     * 成功响应
     * @param <T>
     * @return
     */
    public static <T> JsonResult getJsonResultBySuccess(){
        return new JsonResult(true, null, null);
    }

    public static <T> JsonResult getJsonResultBySuccess(T result) {
        return new JsonResult(true, null, result);
    }

    public static <T> JsonResult getJsonResultBySuccess(String message, T result) {
        return new JsonResult(true, message, result);
    }
    public static <T> JsonResult getJsonResultBySuccess(String message) {
        return new JsonResult(true, message, null);
    }
    /**
     * 失败响应
     * @param <T>
     * @return
     */
    public static <T> JsonResult getJsonResultByFail(){
        return new JsonResult(false, null, null);
    }

    public static <T> JsonResult getJsonResultByFail(T result) {
        return new JsonResult(false, null, result);
    }

    public static <T> JsonResult getJsonResultByFail(String message, T result) {
        return new JsonResult(false, message, result);
    }
    public static <T> JsonResult getJsonResultByFail(String message) {
        return new JsonResult(false, message, null);
    }

}
